'\" t
.TH "SD_EVENT_NOW" "3" "" "systemd 257" "sd_event_now"
.\" -----------------------------------------------------------------
.\" * Define some portability stuff
.\" -----------------------------------------------------------------
.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.\" http://bugs.debian.org/507673
.\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.ie \n(.g .ds Aq \(aq
.el       .ds Aq '
.\" -----------------------------------------------------------------
.\" * set default formatting
.\" -----------------------------------------------------------------
.\" disable hyphenation
.nh
.\" disable justification (adjust text to left margin only)
.ad l
.\" -----------------------------------------------------------------
.\" * MAIN CONTENT STARTS HERE *
.\" -----------------------------------------------------------------
.SH "NAME"
sd_event_now \- Retrieve current event loop iteration timestamp
.SH "SYNOPSIS"
.sp
.ft B
.nf
#include <systemd/sd\-event\&.h>
.fi
.ft
.HP \w'int\ sd_event_now('u
.BI "int sd_event_now(sd_event\ *" "event" ", clockid_t\ " "clock" ", uint64_t\ *" "ret" ");"
.SH "DESCRIPTION"
.PP
\fBsd_event_now()\fR
returns the time when the most recent event loop iteration began\&. A timestamp is taken right after returning from the event sleep, and before dispatching any event sources\&. The
\fIevent\fR
parameter specifies the event loop object to retrieve the timestamp from\&. The
\fIclock\fR
parameter specifies the clock to retrieve the timestamp for, and is one of
\fBCLOCK_REALTIME\fR
(or equivalently
\fBCLOCK_REALTIME_ALARM\fR),
\fBCLOCK_MONOTONIC\fR, or
\fBCLOCK_BOOTTIME\fR
(or equivalently
\fBCLOCK_BOOTTIME_ALARM\fR), see
\fBclock_gettime\fR(2)
for more information on the various clocks\&. The retrieved timestamp is stored in the
\fIret\fR
parameter, in μs since the clock\*(Aqs epoch\&. If this function is invoked before the first event loop iteration, the current time is returned, as reported by
\fBclock_gettime()\fR\&. To distinguish this case from a regular invocation the return value will be positive, and zero when the returned timestamp refers to an actual event loop iteration\&.
.SH "RETURN VALUE"
.PP
If the first event loop iteration has not run yet
\fBsd_event_now()\fR
writes current time to
\fIret\fR
and returns a positive return value\&. Otherwise, it will write the requested timestamp to
\fIret\fR
and return 0\&. On failure, the call returns a negative errno\-style error code\&.
.SS "Errors"
.PP
Returned values may indicate the following problems:
.PP
\fB\-EINVAL\fR
.RS 4
An invalid parameter was passed\&.
.RE
.PP
\fB\-EOPNOTSUPP\fR
.RS 4
Unsupported clock type\&.
.RE
.PP
\fB\-ECHILD\fR
.RS 4
The event loop object was created in a different process, library or module instance\&.
.RE
.SH "NOTES"
.PP
Functions described here are available as a shared library, which can be compiled against and linked to with the
\fBlibsystemd\fR\ \&\fBpkg-config\fR(1)
file\&.
.PP
The code described here uses
\fBgetenv\fR(3), which is declared to be not multi\-thread\-safe\&. This means that the code calling the functions described here must not call
\fBsetenv\fR(3)
from a parallel thread\&. It is recommended to only do calls to
\fBsetenv()\fR
from an early phase of the program when no other threads have been started\&.
.SH "HISTORY"
.PP
\fBsd_event_now()\fR
was added in version 229\&.
.SH "SEE ALSO"
.PP
\fBsystemd\fR(1), \fBsd-event\fR(3), \fBsd_event_new\fR(3), \fBsd_event_add_time\fR(3), \fBclock_gettime\fR(2)
